home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / share / ewl / examples / ewl_dialog_test.c < prev    next >
C/C++ Source or Header  |  2006-01-09  |  4KB  |  146 lines

  1. #include "ewl_test.h"
  2.  
  3. static void
  4. __destroy_test_window(Ewl_Widget *w, void *ev __UNUSED__, 
  5.         void *data __UNUSED__)
  6. {
  7.     ewl_widget_destroy(EWL_WIDGET(w));
  8. }
  9.  
  10. void
  11. __create_window_response(Ewl_Widget *w, void *ev __UNUSED__,
  12.         void *data __UNUSED__)
  13. {
  14.     Ewl_Widget *win_ok     = NULL;
  15.     Ewl_Widget *win_cancel = NULL;
  16.     Ewl_Widget *label;
  17.     char        str[100];
  18.     Ewl_Stock_Type response;
  19.  
  20.     response = ewl_button_stock_type_get(EWL_BUTTON(w));
  21.     if (response == EWL_STOCK_OK)
  22.     {
  23.         if (win_ok != NULL)
  24.         {
  25.             ewl_window_raise (EWL_WINDOW (win_ok));
  26.             return;
  27.         }
  28.         win_ok = ewl_window_new ();
  29.         ewl_window_title_set (EWL_WINDOW (win_ok), "OK Window");
  30.         ewl_window_name_set (EWL_WINDOW (win_ok), "EWL Test Application");
  31.         ewl_window_class_set (EWL_WINDOW (win_ok), "EFL Test Application");
  32.         ewl_object_insets_set (EWL_OBJECT (win_ok), 5, 5, 5, 5);
  33.         ewl_callback_append (win_ok, EWL_CALLBACK_DELETE_WINDOW,
  34.                 __destroy_test_window, NULL);
  35.  
  36.         sprintf (str, "You have clicked on the OK Button\nThe response id is %d.\n", response);
  37.  
  38.         label = ewl_text_new();
  39.         ewl_text_text_set(EWL_TEXT(label), str);
  40.         ewl_container_child_append (EWL_CONTAINER (win_ok), label);
  41.         ewl_widget_show (label);
  42.  
  43.         ewl_widget_show (win_ok);
  44.  
  45.     }
  46.     else if (response == EWL_STOCK_CANCEL)
  47.     {
  48.         if (win_cancel != NULL)
  49.         {
  50.             ewl_window_raise (EWL_WINDOW (win_cancel));
  51.             return;
  52.         }
  53.  
  54.         win_cancel = ewl_window_new ();
  55.         ewl_window_title_set (EWL_WINDOW (win_cancel), "CANCEL Window");
  56.         ewl_window_name_set (EWL_WINDOW (win_cancel), "EWL Test Application");
  57.         ewl_window_class_set (EWL_WINDOW (win_cancel), "EFL Test Application");
  58.         ewl_object_insets_set (EWL_OBJECT (win_cancel), 5, 5, 5, 5);
  59.         ewl_callback_append (win_cancel, EWL_CALLBACK_DELETE_WINDOW,
  60.                 __destroy_test_window, NULL);
  61.  
  62.         sprintf (str, "You have clicked on the CANCEL Button\nThe response id is %d.\n", response);
  63.  
  64.         label = ewl_text_new();
  65.         ewl_text_text_set(EWL_TEXT(label), str);
  66.         ewl_container_child_append (EWL_CONTAINER (win_cancel), label);
  67.         ewl_widget_show (label);
  68.  
  69.         ewl_widget_show (win_cancel);
  70.  
  71.     }
  72. }
  73.  
  74. static void
  75. __destroy_dialog_test_window (Ewl_Widget *w, void *ev __UNUSED__, 
  76.         void *data __UNUSED__)
  77. {
  78.     ewl_widget_destroy (EWL_WIDGET (w));
  79. }
  80.  
  81. void
  82. __create_dialog_test_window (Ewl_Widget * w, void *ev __UNUSED__,
  83.         void *data __UNUSED__)
  84. {
  85.     Ewl_Widget *dialog_win;
  86.     Ewl_Widget *hbox;
  87.     Ewl_Widget *label;
  88.     Ewl_Widget *button;
  89.  
  90.     dialog_win = ewl_dialog_new();
  91.     ewl_window_title_set(EWL_WINDOW (dialog_win), "Dialog Test");
  92.     ewl_window_name_set(EWL_WINDOW (dialog_win), "EWL Test Application");
  93.     ewl_window_class_set(EWL_WINDOW (dialog_win), "EFL Test Application");
  94.     ewl_object_insets_set(EWL_OBJECT (dialog_win), 5, 5, 5, 5);
  95.  
  96.     if (w) 
  97.         ewl_callback_append(dialog_win, EWL_CALLBACK_DELETE_WINDOW,
  98.                 EWL_CALLBACK_FUNCTION(__destroy_dialog_test_window), NULL);
  99.     else
  100.         ewl_callback_append(dialog_win, EWL_CALLBACK_DELETE_WINDOW,
  101.                 __close_main_window, NULL);
  102.  
  103.     ewl_dialog_active_area_set(EWL_DIALOG(dialog_win), EWL_POSITION_TOP);
  104.  
  105.     hbox = ewl_hbox_new();
  106.     ewl_container_child_append(EWL_CONTAINER(dialog_win), hbox);
  107.     ewl_widget_show(hbox);
  108.  
  109.     label = ewl_label_new();
  110.     ewl_label_text_set(EWL_LABEL(label), "blah blah blah");
  111.     ewl_container_child_append(EWL_CONTAINER(hbox), label);
  112.     ewl_widget_show(label);
  113.  
  114.     label = ewl_text_new();
  115.     ewl_text_text_set(EWL_TEXT(label), "This is a test for the Dialog widget");
  116.     ewl_container_child_append(EWL_CONTAINER (hbox), label);
  117.     ewl_widget_show(label);
  118.  
  119.     button = ewl_button_new();
  120.     ewl_container_child_append(EWL_CONTAINER(hbox), button);
  121.     ewl_button_label_set(EWL_BUTTON(button), "tooltip");
  122.     ewl_attach_tooltip_text_set(button, "This is a tooltip");
  123.     ewl_widget_show(button);
  124.  
  125.     ewl_dialog_active_area_set(EWL_DIALOG(dialog_win), EWL_POSITION_BOTTOM);
  126.  
  127.     button = ewl_button_new();
  128.     ewl_button_stock_type_set(EWL_BUTTON(button), EWL_STOCK_OK);
  129.     ewl_container_child_append(EWL_CONTAINER(dialog_win), button);
  130.     ewl_callback_append(button, EWL_CALLBACK_CLICKED,
  131.             __create_window_response, NULL);
  132.     ewl_widget_show(button);
  133.  
  134.     button = ewl_button_new();
  135.     ewl_button_stock_type_set(EWL_BUTTON(button), EWL_STOCK_CANCEL);
  136.     ewl_container_child_append(EWL_CONTAINER(dialog_win), button);
  137.     ewl_callback_append(button, EWL_CALLBACK_CLICKED,
  138.             __create_window_response, NULL);
  139.     ewl_widget_show(button);
  140.  
  141.     ewl_dialog_active_area_set(EWL_DIALOG(dialog_win), EWL_POSITION_TOP);
  142.  
  143.     ewl_widget_show(dialog_win);
  144. }
  145.  
  146.